

package com.hazelcast.client.impl.protocol.codec.custom;

import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.Generated;
import com.hazelcast.client.impl.protocol.codec.builtin.CodecUtil;
import com.hazelcast.client.impl.protocol.codec.builtin.CustomTypeFactory;
import com.hazelcast.client.impl.protocol.codec.builtin.StringCodec;

import static com.hazelcast.client.impl.protocol.ClientMessage.BEGIN_FRAME;
import static com.hazelcast.client.impl.protocol.ClientMessage.END_FRAME;
import static com.hazelcast.client.impl.protocol.codec.builtin.CodecUtil.fastForwardToEndFrame;
import static com.hazelcast.client.impl.protocol.codec.builtin.FixedSizeTypesCodec.*;

@SuppressWarnings("unused")
@Generated("cd31251201375b861dcd020ff5ea83ef")
public final class CacheSimpleEntryListenerConfigCodec {
    private static final int OLD_VALUE_REQUIRED_FIELD_OFFSET = 0;
    private static final int SYNCHRONOUS_FIELD_OFFSET = OLD_VALUE_REQUIRED_FIELD_OFFSET + BOOLEAN_SIZE_IN_BYTES;
    private static final int INITIAL_FRAME_SIZE = SYNCHRONOUS_FIELD_OFFSET + BOOLEAN_SIZE_IN_BYTES;

    private CacheSimpleEntryListenerConfigCodec() {
    }

    public static void encode(ClientMessage clientMessage, com.hazelcast.config.CacheSimpleEntryListenerConfig cacheSimpleEntryListenerConfig) {
        clientMessage.add(BEGIN_FRAME.copy());

        ClientMessage.Frame initialFrame = new ClientMessage.Frame(new byte[INITIAL_FRAME_SIZE]);
        encodeBoolean(initialFrame.content, OLD_VALUE_REQUIRED_FIELD_OFFSET, cacheSimpleEntryListenerConfig.isOldValueRequired());
        encodeBoolean(initialFrame.content, SYNCHRONOUS_FIELD_OFFSET, cacheSimpleEntryListenerConfig.isSynchronous());
        clientMessage.add(initialFrame);

        CodecUtil.encodeNullable(clientMessage, cacheSimpleEntryListenerConfig.getCacheEntryListenerFactory(), StringCodec::encode);
        CodecUtil.encodeNullable(clientMessage, cacheSimpleEntryListenerConfig.getCacheEntryEventFilterFactory(), StringCodec::encode);

        clientMessage.add(END_FRAME.copy());
    }

    public static com.hazelcast.config.CacheSimpleEntryListenerConfig decode(ClientMessage.ForwardFrameIterator iterator) {
        // begin frame
        iterator.next();

        ClientMessage.Frame initialFrame = iterator.next();
        boolean oldValueRequired = decodeBoolean(initialFrame.content, OLD_VALUE_REQUIRED_FIELD_OFFSET);
        boolean synchronous = decodeBoolean(initialFrame.content, SYNCHRONOUS_FIELD_OFFSET);

        java.lang.String cacheEntryListenerFactory = CodecUtil.decodeNullable(iterator, StringCodec::decode);
        java.lang.String cacheEntryEventFilterFactory = CodecUtil.decodeNullable(iterator, StringCodec::decode);

        fastForwardToEndFrame(iterator);

        return CustomTypeFactory.createCacheSimpleEntryListenerConfig(oldValueRequired, synchronous, cacheEntryListenerFactory, cacheEntryEventFilterFactory);
    }
}
